//package com.nhjf.mobile.controller.courses;
//
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//import java.util.Set;
//
//import javax.servlet.http.HttpServletRequest;
//
//import org.apache.commons.lang.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.validation.BindingResult;
//import org.springframework.web.bind.annotation.ModelAttribute;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.ResponseBody;
//import com.nhjf.common.page.Pagination;
//import com.nhjf.mobile.common.util.SysProperties;
//import com.nhjf.model.system.AdminSession;
//import com.nhjf.model.system.Role;
//import com.nhjf.model.system.User;
//import com.nhjf.model.teachers.Courses;
//import com.nhjf.model.teachers.CoursesCollection;
//import com.nhjf.model.teachers.RecentlyStudied;
//import com.nhjf.model.teachers.Teacher;
//import com.nhjf.pojo.qo.system.AdminSessionQo;
//import com.nhjf.pojo.qo.system.UserQo;
//import com.nhjf.pojo.qo.teachers.CoursesCollectionQo;
//import com.nhjf.pojo.qo.teachers.CoursesCommentQo;
//import com.nhjf.pojo.qo.teachers.CoursesQo;
//import com.nhjf.pojo.qo.teachers.RecentlyStudiedQo;
//import com.nhjf.pojo.qo.teachers.TeachersQo;
//import com.nhjf.service.system.AdminSessionService;
//import com.nhjf.service.system.UserService;
//import com.nhjf.service.teachers.CoursesCollectionService;
//import com.nhjf.service.teachers.CoursesCommentService;
//import com.nhjf.service.teachers.CoursesService;
//import com.nhjf.service.teachers.RecentlyStudiedService;
//import com.nhjf.service.teachers.TeachersService;
//
//import net.sf.json.JSONObject;
//
///**
// * @类功能说明：视频课程管理
// * @部门：技术部
// * @作者：龚一凡
// * @版本：V1.0
// */
//@Controller
//@RequestMapping(value = "/coursestest")
//public class CoursesController {
//
//	@Autowired
//	private CoursesService coursesService;
//	@Autowired
//	private UserService userService;
//	@Autowired
//	private TeachersService teacherService;
//	@Autowired
//	private CoursesCommentService coursesCommentService;
//	@Autowired
//	private CoursesCollectionService coursesCollectionService;
//	@Autowired
//	private AdminSessionService adminSessionService;
//	@Autowired
//	private RecentlyStudiedService  recentlyStudiedService;
//	//课程列表
//	@ResponseBody
//	@RequestMapping(value = "/coursespage")
//	public String coursescpage() {
//		Map<String, Object> resMap=new HashMap<String, Object>();
//		Pagination pagination = new Pagination();
//		pagination.setPageSize(8);
//		CoursesQo coursesQo=new CoursesQo();
//		coursesQo.setSeachTeacher(true);
//		coursesQo.setIsReview(1);
//		pagination.setCondition(coursesQo);
//		pagination = coursesService.queryPagination(pagination);
//		List<Courses> coursesList=(List<Courses>)pagination.getList();
//		SysProperties sysProperties=SysProperties.getInstance();
//		String imagePath=sysProperties.get("imagePath");
//		for(Courses courses:coursesList) {
//			TeachersQo teachersQo=new TeachersQo();
//			teachersQo.setTeacherId(courses.getUploader().getId());
//			teachersQo.setSeachUser(true);
//			Teacher teacher=teacherService.queryUnique(teachersQo);
//			courses.setUserId(teacher.getUser().getId());
//			if(StringUtils.isNotEmpty(courses.getUploader().getAvatar())) {
//				if(courses.getUploader().getAvatar().indexOf(imagePath+"/picture/")>=0) {
//				}else {
//					courses.getUploader().setAvatar(imagePath+"/picture/"+courses.getUploader().getAvatar());
//				}
//			}
//			courses.setImge(imagePath+"/img/"+courses.getImge());
//			courses.setVideo("");
//			courses.setCourseintroduction("");
//			courses.setCourseintroduction("");
//			courses.setCourseTypeOneId(null);
//			courses.setCourseTypeTwoId(null);
//			//			courses.set
//		}
//
//		resMap.put("code", "200");
//		resMap.put("message", coursesList);
//		return JSONObject.fromObject(resMap).toString();
//	}
//	/**
//	 * 老师课程列表
//	 * @param teacherId
//	 * @param page
//	 * @return
//	 */
//	@ResponseBody
//	@RequestMapping(value = "/coursesTeacherpage")
//	public String coursesTeacherpage(@RequestParam(value="teacherId", required=true)String teacherId,@RequestParam(value = "page", defaultValue = "1")Integer page) {
//		Map<String, Object> resMap=new HashMap<String, Object>();
//		Pagination pagination = new Pagination();
//		pagination.setPageSize(8);
//		CoursesQo qo=new CoursesQo();
//		qo.setUploader(Long.parseLong(teacherId));
//		qo.setSeachTeacher(true);
//		qo.setIsReview(1);
//		pagination.setCondition(qo);
//
//		pagination.setPageNo(page);
//		pagination = coursesService.queryPagination(pagination);
//		List<Courses> coursesList=(List<Courses>)pagination.getList();
//		SysProperties sysProperties=SysProperties.getInstance();
//		String imagePath=sysProperties.get("imagePath");
//		for(Courses courses:coursesList) {
//			if(StringUtils.isNotEmpty(courses.getUploader().getAvatar())) {
//				if(courses.getUploader().getAvatar().indexOf(imagePath+"/picture/")>=0) {
//				}else {
//					courses.getUploader().setAvatar(imagePath+"/picture/"+courses.getUploader().getAvatar());
//				}
//			}
//			courses.setImge(imagePath+"/img/"+courses.getImge());
//			courses.setVideo("");
//			courses.setCourseintroduction("");
//			courses.setCourseintroduction("");
//			courses.setCourseTypeOneId(null);
//			courses.setCourseTypeTwoId(null);
//			//			courses.set
//		}
//
//		resMap.put("code", "200");
//		resMap.put("message", pagination);
//		return JSONObject.fromObject(resMap).toString();
//	}
//	/**
//	 * 课程详情
//	 * @param coursesId
//	 * @param token
//	 * @return
//	 */
//	@ResponseBody
//	@RequestMapping(value = "/coursesDetails")
//	public String coursesDetails( @RequestParam(value="coursesId", required=true) String coursesId,@RequestParam(value="token", required=false) String token) {
//		Map<String, Object> resMap=new HashMap<String, Object>();
//		CoursesQo qo=new CoursesQo();
//		qo.setCoursesId(Long.parseLong(coursesId));
//		qo.setSeachTeacher(true);
//		Courses courses=coursesService.queryUnique(qo);
//		if(courses!=null) {
//			TeachersQo teacherQo=new TeachersQo();
//			teacherQo.setTeacherId(courses.getUploader().getId());
//			teacherQo.setSeachUser(true);
//			Teacher teacher=teacherService.queryUnique(teacherQo);
//			courses.setSelfintroduction(teacher.getUser().getSelfintroduction());
//			courses.setRqz((courses.getRqz()==null?0:courses.getRqz())+1);
//			coursesService.update(courses);
//			CoursesCommentQo coursesCommentQo=new CoursesCommentQo();
//			coursesCommentQo.setCoursesId(Long.parseLong(coursesId));
//			Integer coursesCommentCount=coursesCommentService.queryCount(coursesCommentQo);
//			CoursesCollectionQo coursesCollectionQo=new CoursesCollectionQo();
//			coursesCollectionQo.setCoursesId(Long.parseLong(coursesId));
//			Integer coursesCollectionCount=coursesCollectionService.queryCount(coursesCollectionQo);
//			courses.setCoursesCommentCount(coursesCommentCount);
//			courses.setCoursesCollectionCount(coursesCollectionCount);
//			courses.setUserId(teacher.getUser().getId());
//			
//			if(StringUtils.isNotEmpty(token)) {
//				AdminSessionQo adminSessionQo=new AdminSessionQo();
//				adminSessionQo.setToken(token);
//				AdminSession adminSession=adminSessionService.queryUnique(adminSessionQo);
//				if(adminSession!=null) {
//					UserQo userQo=new UserQo();
//					userQo.setUserName(adminSession.getLoginName());
//					User user= userService.queryUnique(userQo);
//					if(user!=null) {
//						CoursesCollectionQo coursesCollectionQo1=new CoursesCollectionQo();
//						coursesCollectionQo1.setUserId(user.getId());
//						coursesCollectionQo1.setCoursesId(Long.parseLong(coursesId));
//						CoursesCollection collection1=coursesCollectionService.queryUnique(coursesCollectionQo1);
//						if(collection1!=null) {
//							courses.setIsCollection(1);
//						}
//						RecentlyStudiedQo recentlyStudiedQo=new RecentlyStudiedQo();
//						recentlyStudiedQo.setSeachCourses(true);
//						recentlyStudiedQo.setSeachTeacher(true);
//						recentlyStudiedQo.setSeachUser(true);
//						recentlyStudiedQo.setCoursesId(Long.parseLong(coursesId));
//						recentlyStudiedQo.setUserId(user.getId());
//						RecentlyStudied recentlyStudied1= recentlyStudiedService.queryUnique(recentlyStudiedQo);
//						if(recentlyStudied1!=null) {
//							recentlyStudied1.setRecentLearnTime(new Date());
//							recentlyStudiedService.update(recentlyStudied1);
//						}else {
//							//最近观看
////							RecentlyStudied recentlyStudied=new RecentlyStudied();
////							recentlyStudied.setTeacher(courses.getUploader());
////							recentlyStudied.setUser(user);
////							recentlyStudied.setRecentLearnTime(new Date());
////							recentlyStudied.setCourses(courses);
////							recentlyStudiedService.save(recentlyStudied);
//						}
//
//					}
//				}
//			}
//
//			if(courses.getIsPay()!=null&&courses.getIsPay()==1) {
//				SysProperties sysProperties=SysProperties.getInstance();
//				String imagePath=sysProperties.get("imagePath");
//				if(courses.getUploader()!=null&&courses.getUploader().getAvatar()!=null){
//					courses.getUploader().setAvatar(imagePath+"/picture/"+courses.getUploader().getAvatar());
//				}
//				resMap.put("code", "200");
//				
//
//				courses.setVideo(imagePath+"/videofile/"+courses.getVideo());
//				courses.setImge(imagePath+"/img/"+courses.getImge());
//				resMap.put("message", courses);
//				return JSONObject.fromObject(resMap).toString();
//			}else {
//				resMap.put("code", "200");
//				courses.setVideo("");
//				resMap.put("message", courses);
//				return JSONObject.fromObject(resMap).toString();
//			}
//		}else {
//			resMap.put("code", "500");
//			resMap.put("message", "课程不存在");
//			return JSONObject.fromObject(resMap).toString();
//		}
//	}
//	/**
//	 * 增加人气值
//	 * @param typeOne
//	 * @param typeTwo
//	 * @return
//	 */
//	//	@ResponseBody
//	//	@RequestMapping(value = "/lookCourses")
//	//	public String lookCourses( @RequestParam(value="coursesId", required=true) String coursesId) {
//	//	    Map<String, Object> resMap=new HashMap<String, Object>();
//	//	    CoursesQo qo=new CoursesQo();
//	//	    qo.setCoursesId(Long.parseLong(coursesId));
//	//	    Courses courses=coursesService.queryUnique(qo);
//	//	    if(courses!=null) {
//	//	    	courses.setRqz(courses.getRqz()+1);
//	//	    }
//	//	    coursesService.update(courses);
//	//        resMap.put("code", "200");
//	//        resMap.put("message", "成功");
//	//        return JSONObject.fromObject(resMap).toString();
//	//	}
//	//	
//	/**
//	 * 二级课程列表
//	 * @param typeOne
//	 * @param typeTwo
//	 * @return
//	 */
//	@ResponseBody
//	@RequestMapping(value = "/coursesTypepage")
//	public String coursesTypepage( @RequestParam(value="typeOne", required=true) String typeOne,String typeTwo) {
//		Map<String, Object> resMap=new HashMap<String, Object>();
//		CoursesQo qo=new CoursesQo();
//		qo.setCourseTypeOne(Long.parseLong(typeOne));
//		qo.setCourseTypeTwo(Long.parseLong(typeTwo));
//		qo.setSeachTeacher(true);
//		qo.setIsReview(1);
//		Pagination pagination = new Pagination();
//		pagination.setPageSize(8);
//		pagination.setCondition(qo);
//		pagination = coursesService.queryPagination(pagination);
//		List<Courses> coursesList=(List<Courses>)pagination.getList();
//		SysProperties sysProperties=SysProperties.getInstance();
//		String imagePath=sysProperties.get("imagePath");
//		for(Courses courses:coursesList) {
//			TeachersQo teachersQo=new TeachersQo();
//			teachersQo.setTeacherId(courses.getUploader().getId());
//			teachersQo.setSeachUser(true);
//			Teacher teacher=teacherService.queryUnique(teachersQo);
//			if(StringUtils.isNotEmpty(courses.getUploader().getAvatar())) {
//
//				if(courses.getUploader().getAvatar().indexOf(imagePath+"/picture/")>=0) {
//				}else {
//					courses.getUploader().setAvatar(imagePath+"/picture/"+courses.getUploader().getAvatar());
//				}
//			}
//			courses.setUserId(teacher.getUser().getId());
//			courses.setImge(imagePath+"/img/"+courses.getImge());
//			courses.setVideo("");
//			courses.setCourseintroduction("");
//			courses.setCourseintroduction("");
//			courses.setCourseTypeOneId(null);
//			courses.setCourseTypeTwoId(null);
//			//			courses.set
//		}
//
//		resMap.put("code", "200");
//		resMap.put("message", coursesList);
//		return JSONObject.fromObject(resMap).toString();
//	}
//
//	/**
//	 * 二级课程列表分页
//	 * @param typeOne
//	 * @param typeTwo
//	 * @param page
//	 * @return
//	 */
//	@ResponseBody
//	@RequestMapping(value = "/coursesType")
//	public String coursesType( @RequestParam(value="typeOne", required=true) String typeOne,String typeTwo,@RequestParam(value = "page", defaultValue = "1")Integer page) {
//		Map<String, Object> resMap=new HashMap<String, Object>();
//		CoursesQo qo=new CoursesQo();
//		qo.setCourseTypeOne(Long.parseLong(typeOne));
//		qo.setSeachTeacher(true);
//		qo.setIsReview(1);
//		if(StringUtils.isNotEmpty(typeTwo)&&!"null".equals(typeTwo)) {
//			qo.setCourseTypeTwo(Long.parseLong(typeTwo));
//		}
//		Pagination pagination = new Pagination();
//		pagination.setPageSize(10);
//		pagination.setCondition(qo);
//		pagination.setPageNo(page);
//		pagination = coursesService.queryPagination(pagination);
//		List<Courses> coursesList=(List<Courses>)pagination.getList();
//		SysProperties sysProperties=SysProperties.getInstance();
//		String imagePath=sysProperties.get("imagePath");
//		for(Courses courses:coursesList) {
//			TeachersQo teachersQo=new TeachersQo();
//			teachersQo.setTeacherId(courses.getUploader().getId());
//			teachersQo.setSeachUser(true);
//			Teacher teacher=teacherService.queryUnique(teachersQo);
//			if(StringUtils.isNotEmpty(courses.getUploader().getAvatar())) {
//				if(courses.getUploader().getAvatar().indexOf(imagePath+"/picture/")>=0) {
//
//				}else {
//					courses.getUploader().setAvatar(imagePath+"/picture/"+courses.getUploader().getAvatar());
//				}
//			}
//			courses.setUserId(teacher.getUser().getId());
//			courses.setImge(imagePath+"/img/"+courses.getImge());
//			courses.setVideo("");
//			courses.setCourseintroduction("");
//			courses.setCourseintroduction("");
//			courses.setCourseTypeOneId(null);
//			courses.setCourseTypeTwoId(null);
//			//			courses.set
//		}
//
//		resMap.put("code", "200");
//		resMap.put("message", pagination);
//		return JSONObject.fromObject(resMap).toString();
//	}
//	/**
//	 * 一级课程列表
//	 * @param typeOne
//	 * @param page
//	 * @param typeTwo
//	 * @return
//	 */
//	@ResponseBody
//	@RequestMapping(value = "/coursesTypeOnepage")
//	public String coursesTypeOnepage( @RequestParam(value="typeOne", required=true) String typeOne,@RequestParam(value = "page", defaultValue = "1")Integer page,String typeTwo) {
//		Map<String, Object> resMap=new HashMap<String, Object>();
//		CoursesQo qo=new CoursesQo();
//		qo.setIsReview(1);
//		qo.setCourseTypeOne(Long.parseLong(typeOne));
//		qo.setCourseTypeTwo(Long.parseLong(typeTwo));
//		Pagination pagination = new Pagination();
//		pagination.setPageSize(10);
//		pagination.setPageNo(page);
//		pagination.setCondition(qo);
//		pagination = coursesService.queryPagination(pagination);
//		List<Courses> coursesList=(List<Courses>)pagination.getList();
//		SysProperties sysProperties=SysProperties.getInstance();
//		String imagePath=sysProperties.get("imagePath");
//		for(Courses courses:coursesList) {
//			courses.setImge(imagePath+"/img/"+courses.getImge());
//			courses.setVideo("");
//			courses.setCourseintroduction("");
//			courses.setCourseintroduction("");
//			courses.setCourseTypeOneId(null);
//			courses.setCourseTypeTwoId(null);
//			//			courses.set
//		}
//		pagination.setList(coursesList);
//		resMap.put("code", "200");
//		resMap.put("message", pagination);
//		return JSONObject.fromObject(resMap).toString();
//	}
//	@ResponseBody
//	@RequestMapping(value = "/payLog")
//	public String payLog(){
//		
//		return null;
//	}
//}
